import top.mypath.page.ProgressBarDialog;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.SwingUtilities;
import java.awt.BorderLayout;
import java.awt.Dimension;
public class JProgressBarDemo {
    private JFrame frame;
    private ProgressBarDialog progressBar;
    public JProgressBarDemo() {
        frame = new JFrame("JProgressBar Demo");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setPreferredSize(new Dimension(300, 100));
        progressBar=new ProgressBarDialog(frame,"测试进度条");
        progressBar.setLocationRelativeTo(frame);
        progressBar.setVisible(true);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
    public void start() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i <= 100; i++) {
                    final int value = i;
                    SwingUtilities.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            progressBar.setCompletionRate(value);
                        }
                    });
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }).start();
    }
    public static void main(String[] args) {
        JProgressBarDemo demo = new JProgressBarDemo();
        demo.start();
    }
}
